import logging

class Logger():

    def __init__(self, loggerName, projectName):
        self.logger = logging.getLogger(loggerName)

        self.logger.setLevel(logging.DEBUG)

        sh = logging.StreamHandler()  # 定义输出到控制台的handler
        fh = logging.FileHandler(filename=f"./logs/{projectName}.log", encoding="utf-8")  # 定义输出到文件的handler
        formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s - %(lineno)s - %(message)s")  # 定义输出格式

        # 分别给两个handler设置格式
        sh.setFormatter(formatter)
        fh.setFormatter(formatter)

        # 最后将这两个handler设置到logger身上
        self.logger.addHandler(sh)
        self.logger.addHandler(fh)

    def debug(self, msg):
        self.logger.debug(msg)